<template>
<div id="userForget">
        <BackHeader :header="Header"></BackHeader>
        
            <div class="enroll">
                <div>
                    <mt-field label="用户名：" placeholder="请输入账号" v-model="username"></mt-field>
                    <mt-field label="新密码：" placeholder="请输入新密码" type="password"  v-model="password"></mt-field>
                    <mt-field label="手机号码：" placeholder="请输入手机号码" v-model="phone"><mt-button size="small" @click.native="sendmsg" v-model="data">发送</mt-button></mt-field>
                    <mt-field label="验证码："  placeholder="请输入验证码" v-model="code" ></mt-field>
                </div>
                <div class="forget">
                <mt-button size="large" type="primary" @click="godenglu">提交</mt-button>
                </div>

            </div>

</div>
</template>

<script>
import BackHeader from '../../components/Header/BackHeader.vue'
import { Button } from "mint-ui";
import { MessageBox } from "mint-ui";
import MemberCenterProvider from "@/providers/MemberCenterProvider";
export default {
    name:'userForget',
	data(){
		return{
        Header:'忘记密码',
        username:'',
        password:'',
        phone:'',
        code:'',
        data:'',
        code1:'',
        res:''

		}
	},
    components:{
        BackHeader
    },
    methods:{
       sendmsg(){
    var mobile = this.phone;
    var token = 'b012e604c5ae5348facb1adeee22b6af ';
    var msg = '【API无忧】您的验证码为1234';
    var country_code = '86';   
    let data = {
            'mobile':mobile,
	          'msg':msg,
		        'country_code':country_code,
		        'token':token
          };

          MemberCenterProvider.sendmsgnodejs(data).then(res => {
            this.code1=res.data
            console.log(this.code1);//验证码
          });
    }
    , 
    godenglu(){
        if (!this.username || !this.password ) {
        MessageBox("提示", "请输入账号密码！");
        }else if (!this.phone) {
        MessageBox("提示", "请输入手机号码！");
        }else if (!this.code) {
        MessageBox("提示", "请输入验证码！");
        }else if (this.code!= this.code1) {
        MessageBox("提示","验证码不正确！");
      }else {
        let data = {
            NewForm: {
              userName: this.username,
              password: this.password,
              phone: this.phone,
            }
        };
        MemberCenterProvider.findPsw(data).then(res => {
            console.log(res.data);
            this.res = res.data
            if(this.res=="信息错误"){
                MessageBox("提示","手机号码错误！")
            }else{
                MessageBox.alert("修改成功！").then(action => {
                this.$router.push("/userEnroll");
            });
            }
        })
        
      }
          
        }, 
    }
}
</script>

<style>
 .forget{
     width: 180px;
     height: 190px;
     display: flex;
     margin-top: 30px;
    align-items: center;
    flex-direction: column;
 }
</style>
